// xc_lshop/shop/user/money/record.js
// var util=require('../../utils/util.js')
var util=require('../../../../utils/util.js')

var enddate=util.formatDate(new Date());
var begin=new Date();
var end =new Date(begin.setMonth((new Date().getMonth()-1)));
var startdate=util.formatDate(end);

var min =new Date(begin.setMonth((new Date().getMonth()- 12)));
var mindate=util.formatDate(min);

var actmember = require('../../../../xc/model/member')

Page({
  mixins: [require('../../../../xc/mixins/basicMixin')],

  /**
   * 页面的初始数据
   */
  data: {
    calendarshow:false,
    startdate:startdate,
    enddate:enddate,
    mindate:mindate,
    defaultdate:[startdate,enddate]
  },
  afterlogin: function (options, config, userinfo) {
    var that = this;
    this.setData({
      member:userinfo
    })
    console.log(userinfo)
    if (!userinfo.memberinfo) {
      this.login()
    }
  },
  getpagelist(that, rest, strwhere) {
    if (rest == 1) {
      if (!strwhere) {
        strwhere = {};
      }
      strwhere["status"] = 1;
      strwhere["startdate"] = this.data.startdate;
      strwhere["enddate"] = this.data.enddate;
      that.setData({ modellist: [] });
    }
    actmember.moneyoffset(that, rest, strwhere).then(function (result) {
      var updatemdoel = {};
      if ((result["code"] == "over" && result["obj"]) || result["code"] == "loadmore") { 
        if (rest == 1) {
          updatemdoel["modellist"] = result["obj"]["modellist"];
        }
        else {
          if (result["obj"]["modellist"].length > 0) {
            updatemdoel["modellist"] = that.data.modellist.concat(result["obj"]["modellist"]);
          }
        }
      }
      wx.stopPullDownRefresh();
      that.setData(updatemdoel);
    });
  },
  // 登录注册
  login(e) {
    var that = this;
    app.xc_sys_config.authop.oppower("login").then(function (res) {
      that.setData({
        "member": app.globalData.member
      })
    })
  },
  //申请提现成功刷新纪录
  aftercashout(e){
    var member=e.detail.member
    if(member){
      this.setData({
        member:member
      })
    }
    var that=this;
    that.getpagelist(that,1)
  },
 
  cashoutrecord(e){
    
  },
  // formatDate(date) {
  //   date = new Date(date);
  //   return `${date.getFullYear()}-${date.getMonth() + 1}-${date.getDate()}`;
  // },
  onClose() {
    this.setData({ show: false });
  },
  onConfirm(event) {
 
    const [start, end] = event.detail;

    this.setData({
      calendarshow: false,
      startdate: util.formatDate(start),
      enddate: util.formatDate(end),

    });
  },
  showcalendarblock(){
    this.setData({ calendarshow: true });
  },
  withdrawal:function(){
    var that = this 
    var cashoutcom= that.selectComponent("#cashoutcom");
    cashoutcom.showmodel('money');
   
  },
  xcloaddata: function (options, config) {
   
    var update={};
    if(config && config.money){
      update['moneyconfig']=config.money
    }else{
      update['moneyconfig']={
        cashwith:{
          status:-1
        }
      }
    }
    this.setData(update)


    var that=this;
    this.getpagelist(that, 1)
  },
  /** 
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    var that = this
    this.getpagelist(that, -1)
  },

  
})